package com.qianyu.project.core.mapper;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.qianyu.project.core.bean.Flow;
import com.qianyu.project.core.mapper.provider.FlowProvider;
import com.qianyu.project.vo.FlowVo;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.Map;

/**
 * @author gs
 * @date create in 2020/12/11 17:03
 */
@Repository
public interface FlowMapper {
    /**
     * description: 根据模块查询流程 <br/>
     * author: gs   <br/>
     * date: 2020/12/12 <br/>
     * params: [moduleId] <br/>
     * return: com.qianyu.flow.core.pojo.Flow
     */
    @Select("select * from flow where moduleId=#{value}")
    Flow selectByModule(Integer moduleId);

    /**
     * description: 根据id查询流程 <br/>
     * author: gs   <br/>
     * date: 2021/1/4 <br/>
     * params: [flowId] <br/>
     * return: com.qianyu.project.core.bean.Flow
     */
    @Select("select * from flow where flowId=#{value}")
    Flow selecyById(Integer flowId);

    @Select("select * from flow where flowName like '%${value}%' and isvalid=1")
    Flow selectByName(String flowName);

    @SelectProvider(type = FlowProvider.class,method = "list")
    IPage<Flow> list(IPage<Flow> iPage,@Param("param") Map<String, String> param);



    @Insert("insert into flow values(null,#{flowName},#{flowRemark},#{moduleId},1)")
    @Options(keyColumn = "flowId",keyProperty = "flowId",useGeneratedKeys = true)
    void save(Flow flow);

    @Update("update flow set isvalid=0 where flowId =#{value}")
    void update(Integer flowId);

    @Select("select * from flow where flowName=#{value} and isvalid = 0")
    Flow selectByNameValidisZone(String flowName);

    @Update("update flow set isvalid=1,flowName=#{flowName},flowRemark=#{flowRemark},moduleId=#{moduleId} where flowId =#{flowId}")
    void update1(Flow flow);

    @Select("select * from flow where flowId=#{value} and isvalid=1")
    Flow selectByflowId(Integer flowId);
}
